<!--
 * @Description: 外协单位阶结算
 * @Author: wangwangwang
 * @Date: 2020-11-18 15:34:16
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-01-09 11:54:57
-->
<template>
  <div class="flows-content">
    <el-container>
      <el-main style="margin-bottom: 20px; padding: 0;">
        <el-container direction="vertical">
          <FlowHeader :isReadOnly="readOnly" @saveSubmit="handleSubmit(1)" @sendSubmit="handleSubmit(2)" @handleBackEnd="handleSubmit(3)" @handleCC="handleSubmit(4)" @handleAssign="handleSubmit(5)" @handleBackUp="handleSubmit(6)" @handleAssist="handleSubmit(7)" @handleNode="handleSubmit(8)" @handleNodeImage="handleSubmit(9)" @handleCollection="handleSubmit(10)" />
          <el-main class="info">
            <div>
              <el-input v-model="title" class="flow-title" :disabled="readOnly" placeholder="请输入流程标题"></el-input>
            </div>
            <div class="info-top">
              <div class="left">
                <span>单据号码：{{billCode}}</span>
                <span class="text">制单日期：{{billDate}}</span>
              </div>
              <div class="right">
                <span>发起人：{{applyPerson}}</span>
                <span class="text">状态：{{taskTypeText[taskStatus*1]}}</span>
              </div>
            </div>
            <div>
              <div class="bill_title1">混凝土结算：</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billList.hunPrice" tooltip-effect="dark">
                <el-table-column label="产品名称" align="center" prop="productName"></el-table-column>
                <el-table-column label="签收量（方）" align="center" prop="signForNum"></el-table-column>
                <el-table-column label="基本单价 (元)" align="center" prop="price"></el-table-column>
                <el-table-column label="结算单价（元）" align="center" prop="settlementPrice"></el-table-column>
                <el-table-column label="结算金额（元）" align="center" prop="settlementMoney"></el-table-column>
              </el-table>
              <div v-if="billList.hunPrice.length!==0" class="combined">小计：结算金额【{{combined(billList.hunPrice)}}】</div>
              <div class="bill_title1">运输结算：</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billList.yunPrice" tooltip-effect="dark">
                <el-table-column label="运输方量(方)" align="center" prop="signForNum"></el-table-column>
                <el-table-column label="基本单价（元/方）" align="center" prop="price"></el-table-column>
                <el-table-column label="结算单价（元）" align="center" prop="settlementPrice">
                </el-table-column>
                <el-table-column label="结算金额（元）" align="center" prop="settlementMoney">
                </el-table-column>
              </el-table>
              <div v-if="billList.yunPrice.length!==0" class="combined">小计：结算金额【{{combined(billList.yunPrice)}}】</div>
              <div class="bill_title1">泵送结算：</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billList.pumpPrice" tooltip-effect="dark">
                <el-table-column label="泵送方量(方)" align="center" prop="signForNum"></el-table-column>
                <el-table-column label="基本单价（元/方）" align="center" prop="price"></el-table-column>
                <el-table-column label="结算单价（元）" align="center" prop="settlementPrice">
                </el-table-column>
                <el-table-column label="结算金额（元）" align="center" prop="settlementMoney">
                </el-table-column>
              </el-table>
              <div v-if="billList.pumpPrice.length!==0" class="combined">小计：结算金额【{{combined(billList.pumpPrice)}}】</div>
              <div class="bill_title1">混凝土加工结算：</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billList.jiaPrice" tooltip-effect="dark">
                <el-table-column label="站点" align="center" prop="productName"></el-table-column>
                <el-table-column label="加工方量（方）" align="center" prop="signForNum"></el-table-column>
                <el-table-column label="结算金额（元）" align="center" prop="settlementMoney"></el-table-column>
              </el-table>
              <div v-if="billList.jiaPrice.length!==0" class="combined">小计：结算金额【{{combined(billList.jiaPrice)}}】</div>
              <div class="bill_title">结算合计：</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="totalList" tooltip-effect="dark">
                <el-table-column label="费用项" align="center" prop="name"></el-table-column>
                <el-table-column label="结算金额 (元)" align="center">
                  <template slot-scope="scope">
                    {{scope.row.settlementMoney = combined1(scope.row.price)}}
                  </template>
                </el-table-column>
              </el-table>
              <div v-if="totalList.length!==0" class="combined">合计：{{combined(totalList)}}</div>

            </div>
            <div class="flows-details">
              <FlowContent ref="flowcontent" :title='title' :showSendVisible="showSendVisible" @handleCancel="handleCancel" @sendCode="sendCode" @handleFinish="handleFinish" @handleBusiness="handleBusiness" />
            </div>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import FlowContent from '@/components/WorkFlow/flowContent';
import FlowHeader from '@/components/WorkFlow/flowHeader';
import { getUserInfo } from "@/utils/auth.js";
import {
  querySettledDetaill, updateFinalStatementStatus
} from "@/api/wise/Wise_contactsbusiness/Wise_contactsbusiness.js";
export default {
  components: {
    FlowContent,
    FlowHeader,
  },
  data() {
    return {
      type: 0,
      title: '外协单位阶结算',
      billCode: '',
      billDate: '',
      applyPerson: '',
      taskTypeText: ['发起', '已保存', '审批中', '已完成', '撤销', '不通过'],
      taskStatus: 0,
      readOnly: false,
      showSendVisible: false,
      billList: {
        jiaPrice: [],
        pumpPrice: [],
        yunPrice: [],
        hunPrice: []
      },
      totalList: [
        { name: '混凝土费用', price: 'hunPrice', settlementMoney: 0 },
        { name: '泵送费用', price: 'pumpPrice', settlementMoney: 0 },
        { name: '运输费用', price: 'yunPrice', settlementMoney: 0 },
        { name: '加工费用', price: 'jiaPrice', settlementMoney: 0 }
      ],
      titlestatus: null,
    }
  },
  methods: {
    handleBusiness() {
      const { query } = this.$route;
      const params = {
        process_success: {
          url: '/icps/system/sign/intelligent/proDispatchLogistics/updateFinalStatementStatus',
          data: {
            id: JSON.parse(query.dataContent).id,
            auditStatus: 3
          },
          httpMethod: 'post',
        },
        process_failure: {
          url: '/icps/system/sign/intelligent/proDispatchLogistics/updateFinalStatementStatus',
          data: {
            id: JSON.parse(query.dataContent).id,
            auditStatus: 4
          },
          httpMethod: 'post',
        }
      }
      this.showSendVisible = false;
      this.$refs.flowcontent.handleToFlow(params);
    },
    /**
     * @Description: 
     * @Param: 1为保存，2为最后提交
     * @Author: wangwangwang
     * @param {*} type
     */
    handleFinish(type) {
      const { query } = this.$route;
      if (type == 1) {
        updateFinalStatementStatus({
          id: query.id,
          auditStatus: 2
        })
      }
    },
    handleSubmit(type) {
      const { query } = this.$route;
      if (query.type * 1 === 2 && type === 2 && query.taskType * 1 !== 2) { // 发起流程
        this.showSendVisible = true;
        return
      }
      const data = {
        dataSource: 'sign_Wise_contactsbusiness1',
        dataContent: JSON.stringify({ id: query.id }), // 业务数据
      }
      this.$refs.flowcontent.saveFlows(type, data);
    },
    handleFlowChat() {
      this.$refs.flowcontent.showFlowNode()
    },
    handleCancel() {
      this.showSendVisible = false;
    },
    /**
     * @Description: 回显业务数据
     * @Param: 
     * @Author: wangwangwang
     */
    initFlowsData(id) {
      querySettledDetaill({ id: id }).then(res => {
        this.billList = res.data
      })
      const { query } = this.$route;
      if (query.type * 1 !== 1) {
        this.title = query.taskName;
      }
      this.billCode = query.receiptNumber;
      this.billDate = query.createTime;
    },
    /**结算信息合计*/
    combined(arr) {
      let num = 0
      arr.forEach(res => {
        num = Number(res.settlementMoney) + num
      })
      return num.toFixed(2)
    },
    /**结算信息合计*/
    combined1(index) {
      let num = 0
      this.billList[index].forEach(res => {
        num = Number(res.settlementMoney) + num
      })
      return num
    },
    sendCode(code) {
      this.billCode = code;
    },
  },
  created() {
    const { query } = this.$route;
    this.titlestatus = Number(query.type)
  },
  mounted() {
    const { query } = this.$route;
    if (query.type * 1 === 1) { // 发起流程
      this.initFlowsData(query.id);
      this.$refs.flowcontent.initBaseData('sign_Wise_contactsbusiness1');
      this.billDate = new Date().Format('yyyy-MM-dd hh:mm:ss');
      this.applyPerson = getUserInfo().userRealName;
      return
    }
    this.initFlowsData(JSON.parse(query.dataContent).id);
    this.applyPerson = query.createUserName;
    this.taskStatus = query.taskStatus;
    this.readOnly = true;
  }
}
</script>
<style lang="scss" scoped>
.bill_title {
  font-size: 18px;
  font-weight: 600;
  padding: 15px 0;
}
.bill_title1 {
  font-size: 18px;
  font-weight: 600;
  padding: 20px 0;
}
.bill_subtitle {
  padding: 20px 0;
  > span {
    padding-right: 20px;
  }
  .text {
    color: #000;
  }
}
.combined {
  border: 1px solid #ebeef5;
  text-align: center;
  line-height: 40px;
}
.flows-details {
  margin-top: 20px;
}
.info {
  padding: 0 20px;
  background: #fff;
  .info-top {
    font-size: $font_size;
    color: #000000;
    @include discen_al;
    justify-content: space-between;
    height: 50px;
    border-bottom: 1px #e1e5ed solid;
    .left {
      @include discen_al;
    }
    .text {
      margin-left: 100px;
    }
  }
}
.nav_title {
  @include discen_al;
  align-items: flex-end;
  > div {
    width: 4px;
    height: 24px;
    background: $bg_color;
    margin-right: 10px;
  }
  i {
    margin-left: 5px;
  }
  color: $bg_color;
  font-size: 20px;
  font-weight: bold;
}
.dialoginfo {
  padding: 0;
}
.active {
  border-top: 1px #e1e5ed solid;
  border-right: 1px #e1e5ed solid;
  border-left: 1px #e1e5ed solid;
  background: #fff;
}
.dialoginfo-info {
  border-right: 1px #e1e5ed solid;
  border-left: 1px #e1e5ed solid;
  border-bottom: 1px #e1e5ed solid;
}
/*弹窗*/
.dialoginfo-title {
  > div {
    cursor: pointer;
  }
  height: 48px;
  display: flex;
  background: linear-gradient(
    180deg,
    rgba(250, 252, 255, 1) 0%,
    rgba(245, 247, 250, 1) 100%
  );
  .none {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(calc(100% - 1px) / 2);
    border-bottom: 1px solid #e1e5ed;
    > div {
      line-height: 48px;
      border-bottom: 1px rgba(0, 0, 0, 0) solid;
    }
  }
  .center {
    width: 1px;
    height: 48px;
    background: #e1e5ed;
  }
  .active {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(calc(100% - 1px) / 2);
    border-bottom: 1px solid rgba(0, 0, 0, 0);
    > div {
      color: $bg_color;
      line-height: 48px;
      border-bottom: 1px $bg_color solid;
    }
  }
}
.dialoginfo-info {
  padding: 10px 20px;
  overflow: auto;
  height: calc(85vh - 282px);
  .el-select,
  .el-input,
  .el-date-picker {
    width: 100%;
  }
}
.form-title {
  font-size: 18px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}
</style>